from rest_framework import serializers
from .models import TaskBlock
from equipment.models import Equipment


class TaskBlockSerializer(serializers.ModelSerializer):
    """
    任务块序列化器
    """
    required_device_name = serializers.CharField(source='required_device.device_name', read_only=True)
    required_device_organization = serializers.CharField(source='required_device.organization', read_only=True)
    
    class Meta:
        model = TaskBlock
        fields = [
            'id', 'task_name', 'duration', 'required_device', 
            'required_device_name', 'required_device_organization',
            'daily_device_config', 'status', 'created_at', 'updated_at'
        ]
        read_only_fields = ['created_at', 'updated_at']


class TaskBlockCreateSerializer(serializers.ModelSerializer):
    """
    任务块创建序列化器
    """
    class Meta:
        model = TaskBlock
        fields = [
            'task_name', 'duration', 'required_device', 
            'daily_device_config', 'status'
        ]